home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
comms
/
other
/
slrn
/
slrn_src
/
src
/
startup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
30KB
|
1,228 lines
/* -*- mode: C; mode: fold; -*- */
/* Copyright (c) 1998 John E. Davis (davis@space.mit.edu)
*
* This file is part of slrn.
*
* Slrn is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* Slrn is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with Slrn; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Read startup .slrnrc file */
#include "config.h"
#include "slrnfeat.h"
/*{{{ Include Files */
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <string.h>
#include <slang.h>
#include "jdmacros.h"
#include "slrn.h"
#include "group.h"
#include "misc.h"
#include "art.h"
#include "post.h"
#include "startup.h"
#include "score.h"
#include "util.h"
#include "uudecode.h"
#if SLRN_HAS_MIME
# include "mime.h"
#endif
#if SLRN_HAS_GROUPLENS
# include "grplens.h"
#endif
#if SLRN_HAS_SLANG
# include "interp.h"
#endif
#include "server.h"
#include "chmap.h"
#include "print.h"
#ifdef VMS
# include "vms.h"
#endif
/*}}}*/
/*{{{ Forward Function Declarations */
static int unsetkey_fun (int, SLcmd_Cmd_Table_Type *);
static int setkey_fun (int, SLcmd_Cmd_Table_Type *);
static int server_fun (int, SLcmd_Cmd_Table_Type *);
static int color_fun (int, SLcmd_Cmd_Table_Type *);
static int mono_fun (int, SLcmd_Cmd_Table_Type *);
static int user_data_fun (int, SLcmd_Cmd_Table_Type *);
static int ignore_quote_fun (int, SLcmd_Cmd_Table_Type *);
static int autobaud_fun (int, SLcmd_Cmd_Table_Type *);
static int set_variable_fun (int, SLcmd_Cmd_Table_Type *);
static int nnrp_fun (int, SLcmd_Cmd_Table_Type *);
static int grouplens_fun (int, SLcmd_Cmd_Table_Type *);
static int interpret_fun (int, SLcmd_Cmd_Table_Type *);
static int include_file_fun (int, SLcmd_Cmd_Table_Type *);
static int set_header_format_fun (int, SLcmd_Cmd_Table_Type *);
static int set_visible_headers_fun (int, SLcmd_Cmd_Table_Type *);
/*}}}*/
/*{{{ Static Global Variables */
static int This_Line_Num; /* current line number in startup file */
static char *This_File;
static char *This_Line; /* line being parsed */
char *Server_Object;
char *Post_Object;
static SLcmd_Cmd_Table_Type Slrn_Cmd_Table;
static SLcmd_Cmd_Type Slrn_Startup_File_Cmds[] = /*{{{*/
{
{unsetkey_fun, "unsetkey", "SS"},
{setkey_fun, "setkey", "SSS"},
{server_fun, "server", "SS"},
{color_fun, "color", "SSS"},
{mono_fun, "mono", "SSsss"},
{set_variable_fun, "set", "SG"},
{user_data_fun, "hostname", "S"},
{nnrp_fun, "nnrpaccess", "SSS" },
#define SLRN_MAX_QUOTE_REGEXP 5
{ignore_quote_fun, "ignore_quotes", "Sssss"},
{autobaud_fun, "autobaud", ""},
{grouplens_fun, "grouplens_add", "S"},
{interpret_fun, "interpret", "S"},
{include_file_fun, "include", "S"},
{set_header_format_fun, "header_display_format", "IS"},
{user_data_fun, "scorefile", "S"},
{set_visible_headers_fun, "visible_headers", "S"},
/* The following are considered obsolete */
{user_data_fun, "username", "S"},
{user_data_fun, "replyto", "S"},
{user_data_fun, "organization", "S"},
{user_data_fun, "signature", "S"},
{user_data_fun, "realname", "S"},
{user_data_fun, "followup", "S"},
{user_data_fun, "cc_followup_string", "S"},
{user_data_fun, "quote_string", "S"},
#if SLRN_HAS_DECODE
{user_data_fun, "decode_directory", "S"},
#endif
{user_data_fun, "editor_command", "S"},
{NULL, "", ""}
};
/*}}}*/
/*}}}*/
/*{{{ Public Global Variables */
SLRegexp_Type *Slrn_Ignore_Quote_Regexp [SLRN_MAX_QUOTE_REGEXP + 1];
int Slrn_Autobaud = 0;
char *Slrn_Score_File;
int Slrn_Scroll_By_Page;
/*}}}*/
/*{{{ Utility Functions */
static void exit_malloc_error (void) /*{{{*/
{
if (This_File == NULL)
slrn_exit_error ("Memory Allocation Failure");
slrn_exit_error ("%s: Line %d\n%sMemory Allocation Failure",
This_File, This_Line_Num, This_Line);
}
/*}}}*/
static char *safe_malloc (unsigned int n) /*{{{*/
{
char *s;
s = (char *) SLMALLOC (n);
if (s == NULL) exit_malloc_error ();
return s;
}
/*}}}*/
static void exit_unknown_object (void) /*{{{*/
{
slrn_exit_error ("%s: Error encountered processing line %d\n%s",
This_File, This_Line_Num, This_Line);
}
/*}}}*/
static void issue_obsolete_message (void) /*{{{*/
{
slrn_message ("%s: Command is obsolete on line %d:\n%s",
This_File, This_Line_Num, This_Line);
slrn_message ("The new usage is:\nset %s\n", This_Line);
}
/*}}}*/
/*}}}*/
/*{{{ Set/Unset Key Functions */
static int setkey_fun (int argc, SLcmd_Cmd_Table_Type *table) /*{{{*/
{
char *map = table->string_args[1];
char *fun = table->string_args[2];
char *key = table->string_args[3];
SLKeyMap_List_Type *kmap = NULL;
(void) argc;
if (!strcmp (map, "group")) kmap = Slrn_Group_Keymap;
else if (!strcmp (map, "article")) kmap = Slrn_Article_Keymap;
else if (!strcmp (map, "readline")) kmap = Slrn_RLine_Keymap;
else slrn_exit_error ("%s: line %d:\n%sNo such keymap: %s", This_File, This_Line_Num, This_Line, map);
if (SLang_define_key (key, fun, kmap) != 0)
{
slrn_exit_error ("%s: line %d:\n%serror defining key.", This_File, This_Line_Num, This_Line);
}
return 0;
}
/*}}}*/
static int unsetkey_fun (int argc, SLcmd_Cmd_Table_Type *table) /*{{{*/
{
char *map = table->string_args[1];
char *key = table->string_args[2];
SLKeyMap_List_Type *kmap = NULL;
(void) argc;
if (!strcmp (map, "group")) kmap = Slrn_Group_Keymap;
else if (!strcmp (map, "article")) kmap = Slrn_Article_Keymap;
else slrn_exit_error ("%s: line %d:\n%sNo such keymap: %s",
This_File, This_Line_Num, This_Line, map);
SLang_undefine_key (key, kmap);
return 0;
}
/*}}}*/
/*}}}*/
static int autobaud_fun (int argc, SLcmd_Cmd_Table_Type *table) /*{{{*/
{
(void) argc; (void) table;
Slrn_Autobaud = 1;
return 0;
}
/*}}}*/
static SLRegexp_Type *compile_quote_regexp (char *str) /*{{{*/
{
unsigned char *compiled_pattern_buf;
SLRegexp_Type *r;
compiled_pattern_buf = (unsigned char *) safe_malloc (512);
r = (SLRegexp_Type *) safe_malloc (sizeof (SLRegexp_Type));
r->pat = (unsigned char *) str;
r->buf = compiled_pattern_buf;
r->case_sensitive = 1;
r->buf_len = 512;
if (SLang_regexp_compile (r))
{
slrn_exit_error ("%s: line %d:\n%sInvalid regular expression.",
This_File, This_Line_Num, This_Line);
}
return r;
}
/*}}}*/
static int ignore_quote_fun (int argc, SLcmd_Cmd_Table_Type *table) /*{{{*/
{
unsigned int i;
SLRegexp_Type *r;
if (argc > SLRN_MAX_QUOTE_REGEXP + 1)
{
slrn_exit_error ("%s: line %d:\n%sToo many expressions specified.",
This_File, This_Line_Num, This_Line);
}
for (i = 0; i < SLRN_MAX_QUOTE_REGEXP; i++)
{
r = Slrn_Ignore_Quote_Regexp[i];
if (r != NULL)
{
slrn_free ((char *) r->buf);
SLFREE (r);
Slrn_Ignore_Quote_Regexp [i] = NULL;
}
}
for (i = 1; i < (unsigned int) argc; i++)
{
Slrn_Ignore_Quote_Regexp[i - 1]
= compile_quote_regexp (table->string_args[i]);
}
return 0;
}
/*}}}*/
static int grouplens_fun (int argc, SLcmd_Cmd_Table_Type *table) /*{{{*/
{
(void) argc;
#if SLRN_HAS_GROUPLENS
(void) slrn_grouplens_add_group (table->string_args[1]);
#else
(void) table;
#endif
return 0;
}
/*}}}*/
static int set_visible_headers_fun (int argc, SLcmd_Cmd_Table_Type *table)
{
(void) argc;
return slrn_set_visible_headers (table->string_args[1]);
}
static int set_header_format_fun (int argc, SLcmd_Cmd_Table_Type *table)
{
(void) argc;
return slrn_set_header_format (table->int_args[1], table->string_args